Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 10252 - Common permutation / 10252.cpp
blobe05a40ca15dedf4560c8b840763873171a3b531e
1 #include <iostream>
2 #include <string>
3 #include <algorithm>
4 #include <cassert>
5 using namespace std;
7 int main(){
8 string s,t;
9 while (getline(cin, s) && getline(cin, t)){
10 //assert(s.find(" ") != string::npos);
11 //assert(s.length() > 0 && t.length() > 0);
12 for (int i=0; i<s.size(); ++i){
13 if (!isalpha(s[i]) || !islower(s[i])){
14 s.erase(i, 1);
15 --i;
18 for (int i=0; i<t.size(); ++i){
19 if (!isalpha(t[i]) || !islower(t[i])){
20 t.erase(i, 1);
21 --i;
24 string r = "";
25 sort(s.begin(), s.end());
26 sort(t.begin(), t.end());
27 //cout << s << endl;
28 //cout << t << endl;
29 if (s.size() == 0 || t.size() == 0){
30 cout << endl;
31 continue;
34 if (s == t){
35 cout << s << endl;
36 continue;
38 for (int i=0, j=0; i < s.size() && j < t.size();){
39 if (s[i] == t[j]){
40 r += s[i];
41 ++i;
42 ++j;
43 }else{
44 while (s[i] < t[j]){
45 ++i;
46 if (i == s.size()) break;
48 while (t[j] < s[i]){
49 ++j;
50 if (j == t.size()) break;
54 cout << r << endl;
56 return 0;